# -*- coding: utf-8 -*-
# 作者:飞虎
# 开发时间:2022/5/3 21:52
# 0. 导入需要的包和模块
from PyQt5.Qt import *
import sys

# 1. 创建一个应用程序对象
app = QApplication(sys.argv)
# 2. 控件的操作
# 2.1 创建控件
window = QWidget()
# 2.2 设置控件
window.setWindowTitle('按钮的功能测试-抽象类')
window.resize(500, 500)
# 文本操作
btn = QPushButton(window)
btn.setText("1")
# def plus_one():
# 	print("加一")
# 	num = int(btn.text())+1
# 	btn.setText(str(num))
#
#
# btn.pressed.connect(plus_one)

# 图标操作
icon = QIcon("xxx.png")
btn.setIcon(icon)
size = QSize(50,50)
btn.setIconSize(size)
print(btn.icon())
print(btn.iconSize())

# 快捷键的设置
# btn.setText('a&bc')

btn.setShortcut('Alt+G')
btn.pressed.connect(lambda :print('按钮被点击了'))

# *************自动重复***************开始
# btn.setAutoRepeat(True)
# btn.setAutoRepeatDelay(2000)
# btn.setAutoRepeatInterval(1000)
# print(btn.autoRepeat())
# print(btn.autoRepeatInterval())
# print(btn.autoRepeatDelay())
#
# *************自动重复***************结束

push_button = QPushButton(window)
push_button.setText('这是PushButton')
push_button.move(100,100)

radio_button = QRadioButton(window)
radio_button.setText('这是一个Radio')
radio_button.move(100,150)

checkbox = QCheckBox(window)
checkbox.setText('这是一个复选框')
checkbox.move(100,200)

push_button.setStyleSheet('QPushButton:Pressed{background-color:red;}')

# 把三个按钮都置为按下状态
# push_button.setDown(True)
# radio_button.setDown(True)
# checkbox.setDown(True)
push_button.setCheckable(True)

print(push_button.isCheckable())
print(radio_button.isCheckable())
print(checkbox.isCheckable())
radio_button.setChecked(True)
push_button.setChecked(True)
checkbox.setChecked(True)

print(push_button.isChecked())
print(radio_button.isChecked())
print(checkbox.isChecked())

def cao():
	# print('cao')
	push_button.toggle()
	radio_button.toggle()
	checkbox.toggle()
	# push_button.setChecked(not push_button.isChecked())


btn.pressed.connect(cao)

push_button.setEnabled(False)
radio_button.setEnabled(False)
checkbox.setEnabled(False)

# 2.3 展示控件
window.show()
# 3. 应用程序的执行,进入到消息循环
sys.exit(app.exec_())
